﻿using CraftParameterConfig.Infrastructure.Data;
using System;
using System.Collections.Generic;
using System.Data.Common;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace CraftParameterConfig.Infrastructure.Common
{
    public static class GlobalObjects
    {
        private static int transactionNumber = 0;
        private static DbTransaction dbTransaction;
        private static Dictionary<string, string> sourceValuesObj;
        private static DbContext dbContext = null;
        private static ObjectChange objectChange = null;
        public static DbTransaction DbTransaction
        {
            get
            {
                return dbTransaction;
            }
            set
            {
                dbTransaction = value;
            }
        }
        public static int TransactionNumber 
        { 
            get 
            { 
                return transactionNumber; 
            } 
            set 
            {
                Interlocked.Add(ref transactionNumber, value);
            } 
        }
        public static Dictionary<string, string> SourceValuesObj
        {
            get
            {
                return sourceValuesObj;
            }
            set
            {
                sourceValuesObj = value;
            }
        }
        public static DbContext DbContext
        {
            get 
            {
                if (dbContext == null)
                {
                    dbContext = new DbContext();
                }
                return dbContext;
            }
        }
        public static ObjectChange ObjectChange
        {
            get
            {
                if (objectChange == null)
                {
                    objectChange = new ObjectChange();
                }
                return objectChange;
            }
        }
    }
}
